<!DOCTYPE html>
<html lang="en"><head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   <title>A Universally Unique IDentifier (UUID) URN Namespace</title><script type="application/javascript">
function getMeta(rfcno, container) {

  var xhr = new XMLHttpRequest();
  xhr.open("GET", "https://tools.ietf.org/draft/rfc" + rfcno + "/state.xml", true);
  xhr.onload = function (e) {
    if (xhr.readyState === 4) {
      if (xhr.status === 200) {
        var doc = xhr.responseXML;
        var info = getChildByName(doc.documentElement, "info");
  
        var cont = document.getElementById(container);
        // empty the container
        while (cont.firstChild) {
          cont.removeChild(myNode.firstChild);
        }      
  
        var c = getChildByName(info, "stdstatus");
        if (c !== null) {
          var bld = newElementWithText("b", c.textContent);
          cont.appendChild(bld);
        }
  
        c = getChildByName(info, "updatedby");
        if (c !== null) {
          cont.appendChild(newElement("br"));
          cont.appendChild(newText("Updated by: "));
          appendRfcLinks(cont, c.textContent);
        }
  
        c = getChildByName(info, "obsoletedby");
        if (c !== null) {
          cont.appendChild(newElement("br"));
          cont.appendChild(newText("Obsoleted by: "));
          appendRfcLinks(cont, c.textContent);
        }
        
        c = getChildByName(info, "errata");
        if (c !== null) {
          cont.appendChild(newElement("br"));
          var link = newElementWithText("a", "errata");
          link.setAttribute("href", "http://www.rfc-editor.org/errata_search.php?rfc=" + rfcno);
          var errata = newElementWithText("i", "This document has ");
          errata.appendChild(link);
          errata.appendChild(newText("."));
          cont.appendChild(errata);
        }

        cont.style.display = "block";
      } else {
        console.error(xhr.statusText);
      }
    }
  };
  xhr.onerror = function (e) {
    console.error(xhr.status + " " + xhr.statusText);
  };
  xhr.send(null);
}

// DOM helpers
function newElement(name) {
  return document.createElement(name);
}
function newElementWithText(name, txt) {
  var e = document.createElement(name);
  e.appendChild(newText(txt));
  return e;
}
function newText(text) {
  return document.createTextNode(text);
}

function getChildByName(parent, name) {
  if (parent === null) {
    return null;
  }
  else {
    for (var c = parent.firstChild; c !== null; c = c.nextSibling) {
      if (name == c.nodeName) {
        return c;
      }
    }
    return null;
  }
}

function appendRfcLinks(parent, text) {
  var updates = text.split(",");
  for (var i = 0; i < updates.length; i++) {
    var rfc = updates[i].trim();
    if (rfc.substring(0, 3) == "rfc") {
      var link = newElement("a");
      link.setAttribute("href", "http://tools.ietf.org/html/" + rfc);
      link.appendChild(newText(rfc.substring(3)));
      parent.appendChild(link);
    } else {
      parent.appendChild(newText(rfc));
    }
    if (i != updates.length - 1) {
      parent.appendChild(newText(", "));
    }
  }
}
</script><script type="application/javascript">
function anchorRewrite() {
  map = { };
  if (window.location.hash.length >= 1) {
    var fragid = window.location.hash.substr(1);
    if (fragid) {
      if (! document.getElementById(fragid)) {
        var prefix = "rfc.";
        var mapped = map[fragid];
        if (mapped) {
          window.location.hash = mapped;
        } else if (fragid.indexOf("section-") == 0) {
          window.location.hash = prefix + "section." + fragid.substring(8);
        } else if (fragid.indexOf("appendix-") == 0) {
          window.location.hash = prefix + "section." + fragid.substring(9);
        } else if (fragid.indexOf("s-") == 0) {
          window.location.hash = prefix + "section." + fragid.substring(2);
        } else if (fragid.indexOf("p-") == 0) {
          var r = fragid.substring(2);
          var p = r.indexOf("-");
          if (p >= 0) {
            window.location.hash = prefix + "section." + r.substring(0, p) + ".p." + r.substring(p + 1);
          }
        }
      }
    }  
  }
}
window.addEventListener('hashchange', anchorRewrite);
window.addEventListener('DOMContentLoaded', anchorRewrite);
</script><style type="text/css" title="Xml2Rfc (sans serif)">
a {
  text-decoration: none;
}
a.smpl {
  color: black;
}
a:hover {
  text-decoration: underline;
}
a:active {
  text-decoration: underline;
}
address {
  margin-top: 1em;
  margin-left: 2em;
  font-style: normal;
}
body {
  color: black;
  font-family: cambria, georgia, serif;
  font-size: 12pt;
  margin: 2em auto;
  max-width: 1000px;
}
samp, span.tt, code, pre {
  font-family: consolas, monaco, monospace;
}
cite {
  font-style: normal;
}
dl {
  margin-left: 2em;
}
dl > dt {
  float: left;
  margin-right: 1em;
}
dl.nohang > dt {
  float: none;
}
dl > dd {
  margin-bottom: .5em;
}
dl.compact > dd {
  margin-bottom: .0em;
}
dl > dd > dl {
  margin-top: 0.5em;
}
ul.empty {
  list-style-type: none;
}
ul.empty li {
  margin-top: .5em;
}
dl p {
  margin-left: 0em;
}
dl.reference > dt {
  font-weight: bold;
}
dl.reference > dd {
  margin-left: 3.5em;
}
h1 {
  color: green;
  font-size: 150%;
  line-height: 18pt;
  font-weight: bold;
  text-align: center;
  margin-top: 36pt;
  margin-bottom: 0pt;
}
h2 {
  font-size: 130%;
  line-height: 21pt;
  page-break-after: avoid;
}
h2.np {
  page-break-before: always;
}
h3 {
  font-size: 120%;
  line-height: 15pt;
  page-break-after: avoid;
}
h4 {
  font-size: 110%;
  page-break-after: avoid;
}
h5, h6 {
  page-break-after: avoid;
}
h1 a, h2 a, h3 a, h4 a, h5 a, h6 a {
  color: black;
}
img {
  margin-left: 3em;
}
li {
  margin-left: 2em;
}
ol {
  margin-left: 2em;
}
ol.la {
  list-style-type: lower-alpha;
}
ol.ua {
  list-style-type: upper-alpha;
}
ol p {
  margin-left: 0em;
}
p {
  margin-left: 2em;
}
pre {
  font-size: 11pt;
  margin-left: 3em;
  background-color: lightyellow;
  padding: .25em;
  page-break-inside: avoid;
}
pre.text2 {
  border-style: dotted;
  border-width: 1px;
  background-color: #f0f0f0;
}
pre.inline {
  background-color: white;
  padding: 0em;
  page-break-inside: auto;
}
pre.text {
  border-style: dotted;
  border-width: 1px;
  background-color: #f8f8f8;
}
pre.drawing {
  border-style: solid;
  border-width: 1px;
  background-color: #f8f8f8;
  padding: 2em;
}
table {
  margin-left: 2em;
}
table.header {
  border-spacing: 1px;
  width: 95%;
  font-size: 11pt;
  color: white;
}
td.top {
  vertical-align: top;
}
td.topnowrap {
  vertical-align: top;
  white-space: nowrap;
}
table.header td {
  background-color: gray;
  width: 50%;
}
ul.toc, ul.toc ul {
  list-style: none;
  margin-left: 1.5em;
  padding-left: 0em;
}
ul.toc li {
  line-height: 150%;
  font-weight: bold;
  margin-left: 0em;
}
ul.toc li li {
  line-height: normal;
  font-weight: normal;
  font-size: 11pt;
  margin-left: 0em;
}
li.excluded {
  font-size: 0pt;
}
ul p {
  margin-left: 0em;
}
.filename, h1, h2, h3, h4 {
  font-family: candara, calibri, segoe, optima, arial, sans-serif;
}
.bcp14 {
  font-style: normal;
  text-transform: lowercase;
  font-variant: small-caps;
}
.comment {
  background-color: yellow;
}
.center {
  text-align: center;
}
.error {
  color: red;
  font-style: italic;
  font-weight: bold;
}
.figure {
  font-weight: bold;
  text-align: center;
  font-size: 10pt;
}
.filename {
  color: #333333;
  font-size: 112%;
  font-weight: bold;
  line-height: 21pt;
  text-align: center;
  margin-top: 0pt;
}
.fn {
  font-weight: bold;
}
.left {
  text-align: left;
}
.right {
  text-align: right;
}
.warning {
  font-size: 130%;
  background-color: yellow;
}
.self {
    color: #999999;
    margin-left: .3em;
    text-decoration: none;
    visibility: hidden;
    -webkit-user-select: none; 
    -moz-user-select: none;
    -ms-user-select: none;
}
.self:hover {
    text-decoration: none;
}
p:hover .self {
    visibility: visible;
}
.docstatus {
  border: 1px solid black;
  display: none;
  float: right;
  margin: 2em;
  padding: 1em;
}

@media screen {
  pre.text, pre.text2 {
    width: 69em;
  }
}

@media print {
  .noprint {
    display: none;
  }

  a {
    color: black;
    text-decoration: none;
  }

  table.header {
    width: 90%;
  }

  td.header {
    width: 50%;
    color: black;
    background-color: white;
    vertical-align: top;
    font-size: 110%;
  }

  ul.toc a:last-child::after {
    content: leader('.') target-counter(attr(href), page);
  }

  ul.ind li li a {
    content: target-counter(attr(href), page);
  }

  pre {
    font-size: 10pt;
  }

  .print2col {
    column-count: 2;
    -moz-column-count: 2;
    column-fill: auto;
  }
}
@page {
  @top-left {
       content: "RFC 4122";
  }
  @top-right {
       content: "July 2005";
  }
  @top-center {
       content: "UUID URN";
  }
  @bottom-left {
       content: "Leach, et al.";
  }
  @bottom-center {
       content: "Standards Track";
  }
  @bottom-right {
       content: "[Page " counter(page) "]";
  }
}
@page:first {
    @top-left {
      content: normal;
    }
    @top-right {
      content: normal;
    }
    @top-center {
      content: normal;
    }
}
</style><link rel="Contents" href="#rfc.toc"><link rel="Author" href="#rfc.authors"><link rel="Copyright" href="#rfc.copyright"><link rel="Chapter" title="1 Introduction" href="#rfc.section.1"><link rel="Chapter" title="2 Motivation" href="#rfc.section.2"><link rel="Chapter" title="3 Namespace Registration Template" href="#rfc.section.3"><link rel="Chapter" title="4 Specification" href="#rfc.section.4"><link rel="Chapter" title="5 Community Considerations" href="#rfc.section.5"><link rel="Chapter" title="6 Security Considerations" href="#rfc.section.6"><link rel="Chapter" title="7 Acknowledgments" href="#rfc.section.7"><link rel="Chapter" href="#rfc.section.8" title="8 Normative References"><link rel="Appendix" title="A Appendix A - Sample Implementation" href="#rfc.section.A"><link rel="Appendix" title="B Appendix B - Sample Output of utest" href="#rfc.section.B"><link rel="Appendix" title="C Appendix C - Some Name Space IDs" href="#rfc.section.C"><link rel="Alternate" title="Authoritative ASCII Version" href="http://www.ietf.org/rfc/rfc4122.txt"><link rel="Help" title="RFC-Editor's Status Page" href="http://www.rfc-editor.org/info/rfc4122"><link rel="Help" title="Additional Information on tools.ietf.org" href="http://tools.ietf.org/html/rfc4122"><meta name="generator" content="http://greenbytes.de/tech/webdav/rfc2629.xslt, Revision 1.840, 2016/11/16 05:32:10, XSLT vendor: SAXON 6.5.5 from Michael Kay http://saxon.sf.net/"><meta name="keywords" content="URN, UUID"><link rel="schema.dcterms" href="http://purl.org/dc/terms/"><meta name="dcterms.creator" content="Leach, P."><meta name="dcterms.creator" content="Mealling, M."><meta name="dcterms.creator" content="Salz, R."><meta name="dcterms.identifier" content="urn:ietf:rfc:4122"><meta name="dcterms.issued" content="2005-07"><meta name="dcterms.abstract" content="This specification defines a Uniform Resource Name namespace for UUIDs (Universally Unique IDentifier), also known as GUIDs (Globally Unique IDentifier). A UUID is 128 bits long, and can guarantee uniqueness across space and time. UUIDs were originally used in the Apollo Network Computing System and later in the Open Software Foundation's (OSF) Distributed Computing Environment (DCE), and then in Microsoft Windows platforms.This specification is derived from the DCE specification with the kind permission of the OSF (now known as The Open Group). Information from earlier versions of the DCE specification have been incorporated into this document."><meta name="dcterms.isPartOf" content="urn:issn:2070-1721"><meta name="description" content="This specification defines a Uniform Resource Name namespace for UUIDs (Universally Unique IDentifier), also known as GUIDs (Globally Unique IDentifier). A UUID is 128 bits long, and can guarantee uniqueness across space and time. UUIDs were originally used in the Apollo Network Computing System and later in the Open Software Foundation's (OSF) Distributed Computing Environment (DCE), and then in Microsoft Windows platforms.This specification is derived from the DCE specification with the kind permission of the OSF (now known as The Open Group). Information from earlier versions of the DCE specification have been incorporated into this document."></head><body onload="getMeta(4122,&#34;rfc.meta&#34;);"><header><table class="header" id="rfc.headerblock"><tbody><tr><td class="left">Network Working Group</td><td class="right">P. Leach</td></tr><tr><td class="left">Request for Comments: 4122</td><td class="right">Microsoft</td></tr><tr><td class="left">Category: Standards Track</td><td class="right">M. Mealling</td></tr><tr><td class="left"></td><td class="right">Refactored Networks, LLC</td></tr><tr><td class="left"></td><td class="right">R. Salz</td></tr><tr><td class="left"></td><td class="right">DataPower Technology, Inc.</td></tr><tr><td class="left"></td><td class="right">July 2005</td></tr></tbody></table><div id="rfc.title"><h1>A Universally Unique IDentifier (UUID) URN Namespace</h1></div></header><div id="rfc.meta" class="docstatus"></div><section id="rfc.status"><h2><a href="#rfc.status">Status of this Memo</a></h2><p>This document specifies an Internet standards track protocol for the Internet community, and requests discussion and suggestions for improvements. Please refer to the current edition of the &#8220;Internet Official Protocol Standards&#8221; (STD 1) for the standardization state and status of this protocol. Distribution of this memo is unlimited.</p></section><section id="rfc.copyrightnotice"><h2><a href="#rfc.copyrightnotice">Copyright Notice</a></h2><p>Copyright &copy; The Internet Society (2005). All Rights Reserved.</p></section><section id="rfc.abstract"><h2><a href="#rfc.abstract">Abstract</a></h2><p>This specification defines a Uniform Resource Name namespace for UUIDs (Universally Unique IDentifier), also known as GUIDs (Globally Unique IDentifier). A UUID is 128 bits long, and can guarantee uniqueness across space and time. UUIDs were originally used in the Apollo Network Computing System and later in the Open Software Foundation's (OSF) Distributed Computing Environment (DCE), and then in Microsoft Windows platforms.</p><p>This specification is derived from the DCE specification with the kind permission of the OSF (now known as The Open Group). Information from earlier versions of the DCE specification have been incorporated into this document.</p></section><hr class="noprint"><nav id="rfc.toc"><h2 class="np"><a href="#rfc.toc">Table of Contents</a></h2><ul class="toc"><li><a href="#rfc.section.1">1.</a>&nbsp;&nbsp;&nbsp;<a href="#introduction">Introduction</a></li><li><a href="#rfc.section.2">2.</a>&nbsp;&nbsp;&nbsp;<a href="#motivation">Motivation</a></li><li><a href="#rfc.section.3">3.</a>&nbsp;&nbsp;&nbsp;<a href="#template">Namespace Registration Template</a></li><li><a href="#rfc.section.4">4.</a>&nbsp;&nbsp;&nbsp;<a href="#specification">Specification</a><ul><li><a href="#rfc.section.4.1">4.1.</a>&nbsp;&nbsp;&nbsp;<a href="#format">Format</a><ul><li><a href="#rfc.section.4.1.1">4.1.1.</a>&nbsp;&nbsp;&nbsp;<a href="#variant">Variant</a></li><li><a href="#rfc.section.4.1.2">4.1.2.</a>&nbsp;&nbsp;&nbsp;<a href="#uuid-layout">Layout and Byte Order</a></li><li><a href="#rfc.section.4.1.3">4.1.3.</a>&nbsp;&nbsp;&nbsp;<a href="#version">Version</a></li><li><a href="#rfc.section.4.1.4">4.1.4.</a>&nbsp;&nbsp;&nbsp;<a href="#timestamp">Timestamp</a></li><li><a href="#rfc.section.4.1.5">4.1.5.</a>&nbsp;&nbsp;&nbsp;<a href="#clock-seq">Clock Sequence</a></li><li><a href="#rfc.section.4.1.6">4.1.6.</a>&nbsp;&nbsp;&nbsp;<a href="#node">Node</a></li><li><a href="#rfc.section.4.1.7">4.1.7.</a>&nbsp;&nbsp;&nbsp;<a href="#nil-uuid">Nil UUID</a></li></ul></li><li><a href="#rfc.section.4.2">4.2.</a>&nbsp;&nbsp;&nbsp;<a href="#alg-time">Algorithms for Creating a Time-Based UUID</a><ul><li><a href="#rfc.section.4.2.1">4.2.1.</a>&nbsp;&nbsp;&nbsp;<a href="#alg-time-basic">Basic Algorithm</a></li><li><a href="#rfc.section.4.2.2">4.2.2.</a>&nbsp;&nbsp;&nbsp;<a href="#alg-time-details">Generation Details</a></li></ul></li><li><a href="#rfc.section.4.3">4.3.</a>&nbsp;&nbsp;&nbsp;<a href="#alg-name">Algorithm for Creating a Name-Based UUID</a></li><li><a href="#rfc.section.4.4">4.4.</a>&nbsp;&nbsp;&nbsp;<a href="#alg-rand">Algorithms for Creating a UUID from Truly Random or Pseudo-Random Numbers</a></li><li><a href="#rfc.section.4.5">4.5.</a>&nbsp;&nbsp;&nbsp;<a href="#node-id-no-id">Node IDs that Do Not Identify the Host</a></li></ul></li><li><a href="#rfc.section.5">5.</a>&nbsp;&nbsp;&nbsp;<a href="#community-considerations">Community Considerations</a></li><li><a href="#rfc.section.6">6.</a>&nbsp;&nbsp;&nbsp;<a href="#security-considerations">Security Considerations</a></li><li><a href="#rfc.section.7">7.</a>&nbsp;&nbsp;&nbsp;<a href="#acknowledgments">Acknowledgments</a></li><li><a href="#rfc.section.8">8.</a>&nbsp;&nbsp;&nbsp;<a href="#rfc.references">Normative References</a></li><li><a href="#rfc.section.A">A.</a>&nbsp;&nbsp;&nbsp;<a href="#appendixA">Appendix A - Sample Implementation</a></li><li><a href="#rfc.section.B">B.</a>&nbsp;&nbsp;&nbsp;<a href="#appendixB">Appendix B - Sample Output of utest</a></li><li><a href="#rfc.section.C">C.</a>&nbsp;&nbsp;&nbsp;<a href="#appendixC">Appendix C - Some Name Space IDs</a></li><li><a href="#rfc.authors">Authors' Addresses</a></li><li><a href="#rfc.ipr">Intellectual Property and Copyright Statements</a></li></ul></nav><section id="introduction"><h2 id="rfc.section.1" class="np"><a href="#rfc.section.1">1.</a>&nbsp;<a href="#introduction">Introduction</a></h2><div id="rfc.section.1.p.1"><p>This specification defines a Uniform Resource Name namespace for UUIDs (Universally Unique IDentifier), also known as GUIDs (Globally Unique IDentifier). A UUID is 128 bits long, and requires no central registration process.<a class="self" href="#rfc.section.1.p.1">&para;</a></p></div><div id="rfc.section.1.p.2"><p>The information here is meant to be a concise guide for those wishing to implement services using UUIDs as URNs. Nothing in this document should be construed to override the DCE standards that defined UUIDs.<a class="self" href="#rfc.section.1.p.2">&para;</a></p></div><div id="rfc.section.1.p.3"><p>There is an <a href="#itu687">ITU-T Recommendation and ISO/IEC Standard</a> <cite title="Procedures for the operation of OSI Registration Authorities: Generation and registration of Universally Unique Identifiers (UUIDs) and their use as ASN.1 Object Identifier components">[3]</cite> that are derived from earlier versions of this document. Both sets of specifications have been aligned, and are fully technically compatible. In addition, a global registration function is being provided by the Telecommunications Standardisation Bureau of ITU-T; for details see &lt;<a href="http://www.itu.int/ITU-T/asn1/uuid.html">http://www.itu.int/ITU-T/asn1/uuid.html</a>&gt;.<a class="self" href="#rfc.section.1.p.3">&para;</a></p></div></section><section id="motivation"><h2 id="rfc.section.2"><a href="#rfc.section.2">2.</a>&nbsp;<a href="#motivation">Motivation</a></h2><div id="rfc.section.2.p.1"><p>One of the main reasons for using UUIDs is that no centralized authority is required to administer them (although one format uses IEEE 802 node identifiers, others do not). As a result, generation on demand can be completely automated, and used for a variety of purposes. The UUID generation algorithm described here supports very high allocation rates of up to 10 million per second per machine if necessary, so that they could even be used as transaction IDs.<a class="self" href="#rfc.section.2.p.1">&para;</a></p></div><div id="rfc.section.2.p.2"><p>UUIDs are of a fixed size (128 bits) which is reasonably small compared to other alternatives. This lends itself well to sorting, ordering, and hashing of all sorts, storing in databases, simple allocation, and ease of programming in general.<a class="self" href="#rfc.section.2.p.2">&para;</a></p></div><div id="rfc.section.2.p.3"><p>Since UUIDs are unique and persistent, they make excellent Uniform Resource Names. The unique ability to generate a new UUID without a registration process allows for UUIDs to be one of the URNs with the lowest minting cost.<a class="self" href="#rfc.section.2.p.3">&para;</a></p></div></section><section id="template"><h2 id="rfc.section.3"><a href="#rfc.section.3">3.</a>&nbsp;<a href="#template">Namespace Registration Template</a></h2><div id="rfc.section.3.p.1"><p>Namespace ID: UUID<a class="self" href="#rfc.section.3.p.1">&para;</a></p></div><div id="rfc.section.3.p.2"><p>Registration Information: <a class="self" href="#rfc.section.3.p.2">&para;</a></p><ul class="empty"><li>Registration date: 2003-10-01</li></ul></div><div id="rfc.section.3.p.3"><p>Declared registrant of the namespace: <a class="self" href="#rfc.section.3.p.3">&para;</a></p><ul class="empty"><li>JTC 1/SC6 (ASN.1 Rapporteur Group)</li></ul></div><div id="rfc.section.3.p.4"><p>Declaration of syntactic structure: <a class="self" href="#rfc.section.3.p.4">&para;</a></p><ul class="empty"><li>A UUID is an identifier that is unique across both space and time, with respect to the space of all UUIDs. Since a UUID is a fixed size and contains a time field, it is possible for values to rollover (around A.D. 3400, depending on the specific algorithm used). A UUID can be used for multiple purposes, from tagging objects with an extremely short lifetime, to reliably identifying very persistent objects across a network.</li><li>The internal representation of a UUID is a specific sequence of bits in memory, as described in <a href="#specification" title="Specification">Section&nbsp;4</a>. To accurately represent a UUID as a URN, it is necessary to convert the bit sequence to a string representation.</li><li>Each field is treated as an integer and has its value printed as a zero-filled hexadecimal digit string with the most significant digit first. The hexadecimal values "a" through "f" are output as lower case characters and are case insensitive on input.</li><li>The formal definition of the UUID string representation is provided by the following ABNF <a href="#RFC2234"><cite title="Augmented BNF for Syntax Specifications: ABNF">[7]</cite></a>:<span id="rfc.figure.u.1"><pre>
UUID                   = time-low "-" time-mid "-"
                         time-high-and-version "-"
                         clock-seq-and-reserved
                         clock-seq-low "-" node
time-low               = 4hexOctet
time-mid               = 2hexOctet
time-high-and-version  = 2hexOctet
clock-seq-and-reserved = hexOctet
clock-seq-low          = hexOctet
node                   = 6hexOctet
hexOctet               = hexDigit hexDigit
hexDigit =
      "0" / "1" / "2" / "3" / "4" / "5" / "6" / "7" / "8" / "9" /
      "a" / "b" / "c" / "d" / "e" / "f" /
      "A" / "B" / "C" / "D" / "E" / "F"
    </pre></span> </li><li>The following is an example of the string representation of a UUID as a URN:<span id="rfc.figure.u.2"><pre>
urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6
</pre></span> </li></ul></div><div id="rfc.section.3.p.5" class="avoidbreakafter"><p>Relevant ancillary documentation: <a class="self" href="#rfc.section.3.p.5">&para;</a></p><ul class="empty"><li><a href="#NCA"><cite title="Network Computing Architecture">[1]</cite></a><a href="#DCE"><cite title="DCE: Remote Procedure Call">[2]</cite></a></li></ul></div><div id="rfc.section.3.p.6"><p>Identifier uniqueness considerations: <a class="self" href="#rfc.section.3.p.6">&para;</a></p><ul class="empty"><li>This document specifies three algorithms to generate UUIDs: the first leverages the unique values of 802 MAC addresses to guarantee uniqueness, the second uses pseudo-random number generators, and the third uses cryptographic hashing and application-provided text strings. As a result, the UUIDs generated according to the mechanisms here will be unique from all other UUIDs that have been or will be assigned.</li></ul></div><div id="rfc.section.3.p.7"><p>Identifier persistence considerations: <a class="self" href="#rfc.section.3.p.7">&para;</a></p><ul class="empty"><li>UUIDs are inherently very difficult to resolve in a global sense. This, coupled with the fact that UUIDs are temporally unique within their spatial context, ensures that UUIDs will remain as persistent as possible.</li></ul></div><div id="rfc.section.3.p.8"><p>Process of identifier assignment: <a class="self" href="#rfc.section.3.p.8">&para;</a></p><ul class="empty"><li>Generating a UUID does not require that a registration authority be contacted. One algorithm requires a unique value over space for each generator. This value is typically an IEEE 802 MAC address, usually already available on network-connected hosts. The address can be assigned from an address block obtained from the IEEE registration authority. If no such address is available, or privacy concerns make its use undesirable, <a href="#node-id-no-id" title="Node IDs that Do Not Identify the Host">Section&nbsp;4.5</a> specifies two alternatives. Another approach is to use version 3 or version 4 UUIDs as defined below.</li></ul></div><div id="rfc.section.3.p.9"><p>Process for identifier resolution: <a class="self" href="#rfc.section.3.p.9">&para;</a></p><ul class="empty"><li>Since UUIDs are not globally resolvable, this is not applicable.</li></ul></div><div id="rfc.section.3.p.10"><p>Rules for Lexical Equivalence: <a class="self" href="#rfc.section.3.p.10">&para;</a></p><ul class="empty"><li>Consider each field of the UUID to be an unsigned integer as shown in the table in section <a href="#uuid-layout" title="Layout and Byte Order">Section&nbsp;4.1.2</a>. Then, to compare a pair of UUIDs, arithmetically compare the corresponding fields from each UUID in order of significance and according to their data type. Two UUIDs are equal if and only if all the corresponding fields are equal.</li><li>As an implementation note, equality comparison can be performed on many systems by doing the appropriate byte-order canonicalization, and then treating the two UUIDs as 128-bit unsigned integers.</li><li>UUIDs, as defined in this document, can also be ordered lexicographically. For a pair of UUIDs, the first one follows the second if the most significant field in which the UUIDs differ is greater for the first UUID. The second precedes the first if the most significant field in which the UUIDs differ is greater for the second UUID.</li></ul></div><div id="rfc.section.3.p.11"><p>Conformance with URN Syntax: <a class="self" href="#rfc.section.3.p.11">&para;</a></p><ul class="empty"><li>The string representation of a UUID is fully compatible with the URN syntax. When converting from a bit-oriented, in-memory representation of a UUID into a URN, care must be taken to strictly adhere to the byte order issues mentioned in the string representation section.</li></ul></div><div id="rfc.section.3.p.12"><p>Validation mechanism: <a class="self" href="#rfc.section.3.p.12">&para;</a></p><ul class="empty"><li>Apart from determining whether the timestamp portion of the UUID is in the future and therefore not yet assignable, there is no mechanism for determining whether a UUID is 'valid'.</li></ul></div><div id="rfc.section.3.p.13"><p>Scope: <a class="self" href="#rfc.section.3.p.13">&para;</a></p><ul class="empty"><li>UUIDs are global in scope.</li></ul></div></section><section id="specification"><h2 id="rfc.section.4"><a href="#rfc.section.4">4.</a>&nbsp;<a href="#specification">Specification</a></h2><section id="format"><h3 id="rfc.section.4.1"><a href="#rfc.section.4.1">4.1.</a>&nbsp;<a href="#format">Format</a></h3><div id="rfc.section.4.1.p.1"><p>The UUID format is 16 octets; some bits of the eight octet variant field specified below determine finer structure.<a class="self" href="#rfc.section.4.1.p.1">&para;</a></p></div><section id="variant"><h4 id="rfc.section.4.1.1"><a href="#rfc.section.4.1.1">4.1.1.</a>&nbsp;<a href="#variant">Variant</a></h4><div id="rfc.section.4.1.1.p.1"><p>The variant field determines the layout of the UUID. That is, the interpretation of all other bits in the UUID depends on the setting of the bits in the variant field. As such, it could more accurately be called a type field; we retain the original term for compatibility. The variant field consists of a variable number of the most significant bits of octet 8 of the UUID.<a class="self" href="#rfc.section.4.1.1.p.1">&para;</a></p></div><div id="rfc.section.4.1.1.p.2"><p>The following table lists the contents of the variant field, where the letter "x" indicates a "don't-care" value. <a class="self" href="#rfc.section.4.1.1.p.2">&para;</a></p><span id="rfc.figure.u.3"><pre>
Msb0  Msb1  Msb2  Description

 0     x     x    Reserved, NCS backward compatibility.

 1     0     x    The variant specified in this document.

 1     1     0    Reserved, Microsoft Corporation backward
                  compatibility

 1     1     1    Reserved for future definition.
</pre></span></div><div id="rfc.section.4.1.1.p.3"><p>Interoperability, in any form, with variants other than the one defined here is not guaranteed, and is not likely to be an issue in practice.<a class="self" href="#rfc.section.4.1.1.p.3">&para;</a></p></div></section><section id="uuid-layout"><h4 id="rfc.section.4.1.2"><a href="#rfc.section.4.1.2">4.1.2.</a>&nbsp;<a href="#uuid-layout">Layout and Byte Order</a></h4><div id="rfc.section.4.1.2.p.1"><p>To minimize confusion about bit assignments within octets, the UUID record definition is defined only in terms of fields that are integral numbers of octets. The fields are presented with the most significant one first.<a class="self" href="#rfc.section.4.1.2.p.1">&para;</a></p><span id="rfc.figure.u.4"><pre>
Field                  Data Type     Octet  Note
                                     #

time_low               unsigned 32   0-3    The low field of the
                       bit integer          timestamp

time_mid               unsigned 16   4-5    The middle field of the
                       bit integer          timestamp

time_hi_and_version    unsigned 16   6-7    The high field of the
                       bit integer          timestamp multiplexed
                                            with the version number

clock_seq_hi_and_rese  unsigned 8    8      The high field of the
rved                   bit integer          clock sequence
                                            multiplexed with the
                                            variant

clock_seq_low          unsigned 8    9      The low field of the
                       bit integer          clock sequence

node                   unsigned 48   10-15  The spatially unique
                       bit integer          node identifier
</pre></span></div><div id="rfc.section.4.1.2.p.2" class="avoidbreakafter"><p>In the absence of explicit application or presentation protocol specification to the contrary, a UUID is encoded as a 128-bit object, as follows:<a class="self" href="#rfc.section.4.1.2.p.2">&para;</a></p></div><div id="rfc.section.4.1.2.p.3"><p>The fields are encoded as 16 octets, with the sizes and order of the fields defined above, and with each field encoded with the Most Significant Byte first (known as network byte order). Note that the field names, particularly for multiplexed fields, follow historical practice.<a class="self" href="#rfc.section.4.1.2.p.3">&para;</a></p><span id="rfc.figure.u.5"><pre>
0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                          time_low                             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|       time_mid                |         time_hi_and_version   |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|clk_seq_hi_res |  clk_seq_low  |         node (0-1)            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                         node (2-5)                            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
</pre></span></div></section><section id="version"><h4 id="rfc.section.4.1.3"><a href="#rfc.section.4.1.3">4.1.3.</a>&nbsp;<a href="#version">Version</a></h4><div id="rfc.section.4.1.3.p.1"><p>The version number is in the most significant 4 bits of the time stamp (bits 4 through 7 of the time_hi_and_version field).<a class="self" href="#rfc.section.4.1.3.p.1">&para;</a></p></div><div id="rfc.section.4.1.3.p.2"><p>The following table lists the currently-defined versions for this UUID variant.<a class="self" href="#rfc.section.4.1.3.p.2">&para;</a></p><span id="rfc.figure.u.6"><pre>
Msb0  Msb1  Msb2  Msb3   Version  Description

 0     0     0     1        1     The time-based version
                                  specified in this document.

 0     0     1     0        2     DCE Security version, with
                                  embedded POSIX UIDs.

 0     0     1     1        3     The name-based version
                                  specified in this document
                                  that uses MD5 hashing.

 0     1     0     0        4     The randomly or pseudo-
                                  randomly generated version
                                  specified in this document.

 0     1     0     1        5     The name-based version
                                  specified in this document
                                  that uses SHA-1 hashing.
</pre></span><p> The version is more accurately a sub-type; again, we retain the term for compatibility.</p></div></section><section id="timestamp"><h4 id="rfc.section.4.1.4"><a href="#rfc.section.4.1.4">4.1.4.</a>&nbsp;<a href="#timestamp">Timestamp</a></h4><div id="rfc.section.4.1.4.p.1"><p>The timestamp is a 60-bit value. For UUID version 1, this is represented by Coordinated Universal Time (UTC) as a count of 100-nanosecond intervals since 00:00:00.00, 15 October 1582 (the date of Gregorian reform to the Christian calendar).<a class="self" href="#rfc.section.4.1.4.p.1">&para;</a></p></div><div id="rfc.section.4.1.4.p.2"><p>For systems that do not have UTC available, but do have the local time, they may use that instead of UTC, as long as they do so consistently throughout the system. However, this is not recommended since generating the UTC from local time only needs a time zone offset.<a class="self" href="#rfc.section.4.1.4.p.2">&para;</a></p></div><div id="rfc.section.4.1.4.p.3"><p>For UUID version 3 or 5, the timestamp is a 60-bit value constructed from a name as described in <a href="#alg-name" title="Algorithm for Creating a Name-Based UUID">Section&nbsp;4.3</a>.<a class="self" href="#rfc.section.4.1.4.p.3">&para;</a></p></div><div id="rfc.section.4.1.4.p.4"><p>For UUID version 4, the timestamp is a randomly or pseudo-randomly generated 60-bit value, as described in <a href="#alg-rand" title="Algorithms for Creating a UUID from Truly Random or Pseudo-Random Numbers">Section&nbsp;4.4</a>.<a class="self" href="#rfc.section.4.1.4.p.4">&para;</a></p></div></section><section id="clock-seq"><h4 id="rfc.section.4.1.5"><a href="#rfc.section.4.1.5">4.1.5.</a>&nbsp;<a href="#clock-seq">Clock Sequence</a></h4><div id="rfc.section.4.1.5.p.1"><p>For UUID version 1, the clock sequence is used to help avoid duplicates that could arise when the clock is set backwards in time or if the node ID changes.<a class="self" href="#rfc.section.4.1.5.p.1">&para;</a></p></div><div id="rfc.section.4.1.5.p.2"><p>If the clock is set backwards, or might have been set backwards (e.g., while the system was powered off), and the UUID generator can not be sure that no UUIDs were generated with timestamps larger than the value to which the clock was set, then the clock sequence has to be changed. If the previous value of the clock sequence is known, it can just be incremented; otherwise it should be set to a random or high-quality pseudo-random value.<a class="self" href="#rfc.section.4.1.5.p.2">&para;</a></p></div><div id="rfc.section.4.1.5.p.3"><p>Similarly, if the node ID changes (e.g., because a network card has been moved between machines), setting the clock sequence to a random number minimizes the probability of a duplicate due to slight differences in the clock settings of the machines. If the value of clock sequence associated with the changed node ID were known, then the clock sequence could just be incremented, but that is unlikely.<a class="self" href="#rfc.section.4.1.5.p.3">&para;</a></p></div><div id="rfc.section.4.1.5.p.4"><p>The clock sequence <em class="bcp14">MUST</em> be originally (i.e., once in the lifetime of a system) initialized to a random number to minimize the correlation across systems. This provides maximum protection against node identifiers that may move or switch from system to system rapidly. The initial value <em class="bcp14">MUST NOT</em> be correlated to the node identifier.<a class="self" href="#rfc.section.4.1.5.p.4">&para;</a></p></div><div id="rfc.section.4.1.5.p.5"><p>For UUID version 3 or 5, the clock sequence is a 14-bit value constructed from a name as described in <a href="#alg-name" title="Algorithm for Creating a Name-Based UUID">Section&nbsp;4.3</a>.<a class="self" href="#rfc.section.4.1.5.p.5">&para;</a></p></div><div id="rfc.section.4.1.5.p.6"><p>For UUID version 4, clock sequence is a randomly or pseudo-randomly generated 14-bit value as described in <a href="#alg-rand" title="Algorithms for Creating a UUID from Truly Random or Pseudo-Random Numbers">Section&nbsp;4.4</a>.<a class="self" href="#rfc.section.4.1.5.p.6">&para;</a></p></div></section><section id="node"><h4 id="rfc.section.4.1.6"><a href="#rfc.section.4.1.6">4.1.6.</a>&nbsp;<a href="#node">Node</a></h4><div id="rfc.section.4.1.6.p.1"><p>For UUID version 1, the node field consists of an IEEE 802 MAC address, usually the host address. For systems with multiple IEEE 802 addresses, any available one can be used. The lowest addressed octet (octet number 10) contains the global/local bit and the unicast/multicast bit, and is the first octet of the address transmitted on an 802.3 LAN.<a class="self" href="#rfc.section.4.1.6.p.1">&para;</a></p></div><div id="rfc.section.4.1.6.p.2"><p>For systems with no IEEE address, a randomly or pseudo-randomly generated value may be used; see <a href="#node-id-no-id" title="Node IDs that Do Not Identify the Host">Section&nbsp;4.5</a>. The multicast bit must be set in such addresses, in order that they will never conflict with addresses obtained from network cards.<a class="self" href="#rfc.section.4.1.6.p.2">&para;</a></p></div><div id="rfc.section.4.1.6.p.3"><p>For UUID version 3 or 5, the node field is a 48-bit value constructed from a name as described in <a href="#alg-name" title="Algorithm for Creating a Name-Based UUID">Section&nbsp;4.3</a>.<a class="self" href="#rfc.section.4.1.6.p.3">&para;</a></p></div><div id="rfc.section.4.1.6.p.4"><p>For UUID version 4, the node field is a randomly or pseudo-randomly generated 48-bit value as described in <a href="#alg-rand" title="Algorithms for Creating a UUID from Truly Random or Pseudo-Random Numbers">Section&nbsp;4.4</a>.<a class="self" href="#rfc.section.4.1.6.p.4">&para;</a></p></div></section><section id="nil-uuid"><h4 id="rfc.section.4.1.7"><a href="#rfc.section.4.1.7">4.1.7.</a>&nbsp;<a href="#nil-uuid">Nil UUID</a></h4><div id="rfc.section.4.1.7.p.1"><p>The nil UUID is special form of UUID that is specified to have all 128 bits set to zero.<a class="self" href="#rfc.section.4.1.7.p.1">&para;</a></p></div></section></section><section id="alg-time"><h3 id="rfc.section.4.2"><a href="#rfc.section.4.2">4.2.</a>&nbsp;<a href="#alg-time">Algorithms for Creating a Time-Based UUID</a></h3><div id="rfc.section.4.2.p.1"><p>Various aspects of the algorithm for creating a version 1 UUID are discussed in the following sections.<a class="self" href="#rfc.section.4.2.p.1">&para;</a></p></div><section id="alg-time-basic"><h4 id="rfc.section.4.2.1"><a href="#rfc.section.4.2.1">4.2.1.</a>&nbsp;<a href="#alg-time-basic">Basic Algorithm</a></h4><div id="rfc.section.4.2.1.p.1"><p>The following algorithm is simple, correct, and inefficient:  <a class="self" href="#rfc.section.4.2.1.p.1">&para;</a></p><ul><li>Obtain a system-wide global lock</li><li>From a system-wide shared stable store (e.g., a file), read the UUID generator state: the values of the timestamp, clock sequence, and node ID used to generate the last UUID.</li><li>Get the current time as a 60-bit count of 100-nanosecond intervals since 00:00:00.00, 15 October 1582.</li><li>Get the current node ID.</li><li>If the state was unavailable (e.g., non-existent or corrupted), or the saved node ID is different than the current node ID, generate a random clock sequence value.</li><li>If the state was available, but the saved time stamp is later than the current timestamp, increment the clock sequence value.</li><li>Save the state (current time stamp, clock sequence, and node ID) back to the stable store.</li><li>Release the global lock.</li><li>Format a UUID from the current timestamp, clock sequence, and node ID values according to the steps in <a href="#alg-time-details" title="Generation Details">Section&nbsp;4.2.2</a>.</li></ul></div><div id="rfc.section.4.2.1.p.2"><p>If UUIDs do not need to be frequently generated, the above algorithm may be perfectly adequate. For higher performance requirements, however, issues with the basic algorithm include:  <a class="self" href="#rfc.section.4.2.1.p.2">&para;</a></p><ul><li>Reading the state from stable storage each time is inefficient.</li><li>The resolution of the system clock may not be 100-nanoseconds.</li><li>Writing the state to stable storage each time is inefficient.</li><li>Sharing the state across process boundaries may be inefficient.</li></ul></div><div id="rfc.section.4.2.1.p.3"><p>Each of these issues can be addressed in a modular fashion by local improvements in the functions that read and write the state and read the clock. We address each of them in turn in the following sections.<a class="self" href="#rfc.section.4.2.1.p.3">&para;</a></p></div><section id="read-stable"><h5 id="rfc.section.4.2.1.1"><a href="#rfc.section.4.2.1.1">4.2.1.1.</a>&nbsp;<a href="#read-stable">Reading Stable Storage</a></h5><div id="rfc.section.4.2.1.1.p.1"><p>The state only needs to be read from stable storage once at boot time, if it is read into a system-wide shared volatile store (and updated whenever the stable store is updated).<a class="self" href="#rfc.section.4.2.1.1.p.1">&para;</a></p></div><div id="rfc.section.4.2.1.1.p.2"><p>If an implementation does not have any stable store available, then it can always say that the values were unavailable. This is the least desirable implementation because it will increase the frequency of creation of new clock sequence numbers, which increases the probability of duplicates.<a class="self" href="#rfc.section.4.2.1.1.p.2">&para;</a></p></div><div id="rfc.section.4.2.1.1.p.3"><p>If the node ID can never change (e.g., the net card is inseparable from the system), or if any change also reinitializes the clock sequence to a random value, then instead of keeping it in stable store, the current node ID may be returned.<a class="self" href="#rfc.section.4.2.1.1.p.3">&para;</a></p></div></section><section id="clock-resolution"><h5 id="rfc.section.4.2.1.2"><a href="#rfc.section.4.2.1.2">4.2.1.2.</a>&nbsp;<a href="#clock-resolution">System Clock Resolution</a></h5><div id="rfc.section.4.2.1.2.p.1"><p>The timestamp is generated from the system time, whose resolution may be less than the resolution of the UUID timestamp.<a class="self" href="#rfc.section.4.2.1.2.p.1">&para;</a></p></div><div id="rfc.section.4.2.1.2.p.2"><p>If UUIDs do not need to be frequently generated, the time stamp can simply be the system time multiplied by the number of 100-nanosecond intervals per system time interval.<a class="self" href="#rfc.section.4.2.1.2.p.2">&para;</a></p></div><div id="rfc.section.4.2.1.2.p.3"><p>If a system overruns the generator by requesting too many UUIDs within a single system time interval, the UUID service <em class="bcp14">MUST</em> either return an error, or stall the UUID generator until the system clock catches up.<a class="self" href="#rfc.section.4.2.1.2.p.3">&para;</a></p></div><div id="rfc.section.4.2.1.2.p.4"><p>A high resolution timestamp can be simulated by keeping a count of the number of UUIDs that have been generated with the same value of the system time, and using it to construct the low order bits of the timestamp. The count will range between zero and the number of 100-nanosecond intervals per system time interval.<a class="self" href="#rfc.section.4.2.1.2.p.4">&para;</a></p></div><div id="rfc.section.4.2.1.2.p.5"><p>Note: If the processors overrun the UUID generation frequently, additional node identifiers can be allocated to the system, which will permit higher speed allocation by making multiple UUIDs potentially available for each time stamp value.<a class="self" href="#rfc.section.4.2.1.2.p.5">&para;</a></p></div></section><section id="write-stable"><h5 id="rfc.section.4.2.1.3"><a href="#rfc.section.4.2.1.3">4.2.1.3.</a>&nbsp;<a href="#write-stable">Writing Stable Storage</a></h5><div id="rfc.section.4.2.1.3.p.1"><p>The state does not always need to be written to stable store every time a UUID is generated. The timestamp in the stable store can be periodically set to a value larger than any yet used in a UUID. As long as the generated UUIDs have timestamps less than that value, and the clock sequence and node ID remain unchanged, only the shared volatile copy of the state needs to be updated. Furthermore, if the time stamp value in stable store is in the future by less than the typical time it takes the system to reboot, a crash will not cause a reinitialization of the clock sequence.<a class="self" href="#rfc.section.4.2.1.3.p.1">&para;</a></p></div></section><section id="share-state"><h5 id="rfc.section.4.2.1.4"><a href="#rfc.section.4.2.1.4">4.2.1.4.</a>&nbsp;<a href="#share-state">Sharing State Across Processes</a></h5><div id="rfc.section.4.2.1.4.p.1"><p>If it is too expensive to access shared state each time a UUID is generated, then the system-wide generator can be implemented to allocate a block of time stamps each time it is called; a per-process generator can allocate from that block until it is exhausted.<a class="self" href="#rfc.section.4.2.1.4.p.1">&para;</a></p></div></section></section><section id="alg-time-details"><h4 id="rfc.section.4.2.2"><a href="#rfc.section.4.2.2">4.2.2.</a>&nbsp;<a href="#alg-time-details">Generation Details</a></h4><div id="rfc.section.4.2.2.p.1"><p>Version 1 UUIDs are generated according to the following algorithm:  <a class="self" href="#rfc.section.4.2.2.p.1">&para;</a></p><ul><li>Determine the values for the UTC-based timestamp and clock sequence to be used in the UUID, as described in <a href="#alg-time-basic" title="Basic Algorithm">Section&nbsp;4.2.1</a>.</li><li>For the purposes of this algorithm, consider the timestamp to be a 60-bit unsigned integer and the clock sequence to be a 14-bit unsigned integer. Sequentially number the bits in a field, starting with zero for the least significant bit.</li><li>Set the time_low field equal to the least significant 32 bits (bits zero through 31) of the timestamp in the same order of significance.</li><li>Set the time_mid field equal to bits 32 through 47 from the timestamp in the same order of significance.</li><li>Set the 12 least significant bits (bits zero through 11) of the time_hi_and_version field equal to bits 48 through 59 from the timestamp in the same order of significance.</li><li>Set the four most significant bits (bits 12 through 15) of the time_hi_and_version field to the 4-bit version number corresponding to the UUID version being created, as shown in the table above.</li><li>Set the clock_seq_low field to the eight least significant bits (bits zero through 7) of the clock sequence in the same order of significance.</li><li>Set the 6 least significant bits (bits zero through 5) of the clock_seq_hi_and_reserved field to the 6 most significant bits (bits 8 through 13) of the clock sequence in the same order of significance.</li><li>Set the two most significant bits (bits 6 and 7) of the clock_seq_hi_and_reserved to zero and one, respectively.</li><li>Set the node field to the 48-bit IEEE address in the same order of significance as the address.</li></ul></div></section></section><section id="alg-name"><h3 id="rfc.section.4.3"><a href="#rfc.section.4.3">4.3.</a>&nbsp;<a href="#alg-name">Algorithm for Creating a Name-Based UUID</a></h3><div id="rfc.section.4.3.p.1"><p>The version 3 or 5 UUID is meant for generating UUIDs from "names" that are drawn from, and unique within, some "name space". The concept of name and name space should be broadly construed, and not limited to textual names. For example, some name spaces are the domain name system, URLs, ISO Object IDs (OIDs), X.500 Distinguished Names (DNs), and reserved words in a programming language. The mechanisms or conventions used for allocating names and ensuring their uniqueness within their name spaces are beyond the scope of this specification.<a class="self" href="#rfc.section.4.3.p.1">&para;</a></p></div><div id="rfc.section.4.3.p.2"><p>The requirements for these types of UUIDs are as follows:  <a class="self" href="#rfc.section.4.3.p.2">&para;</a></p><ul><li>The UUIDs generated at different times from the same name in the same namespace <em class="bcp14">MUST</em> be equal.</li><li>The UUIDs generated from two different names in the same namespace should be different (with very high probability).</li><li>The UUIDs generated from the same name in two different namespaces should be different with (very high probability).</li><li>If two UUIDs that were generated from names are equal, then they were generated from the same name in the same namespace (with very high probability).</li></ul></div><div id="rfc.section.4.3.p.3"><p>The algorithm for generating a UUID from a name and a name space are as follows:  <a class="self" href="#rfc.section.4.3.p.3">&para;</a></p><ul><li>Allocate a UUID to use as a "name space ID" for all UUIDs generated from names in that name space; see <a href="#appendixC" title="Appendix C - Some Name Space IDs">Appendix&nbsp;C</a> for some pre-defined values.</li><li>Choose either <a href="#RFC1321">MD5</a> <cite title="The MD5 Message-Digest Algorithm">[4]</cite> or <a href="#FIPS.180-1.1995">SHA-1</a> <cite title="Secure Hash Standard">[8]</cite> as the hash algorithm; If backward compatibility is not an issue, SHA-1 is preferred.</li><li>Convert the name to a canonical sequence of octets (as defined by the standards or conventions of its name space); put the name space ID in network byte order.</li><li>Compute the hash of the name space ID concatenated with the name.</li><li>Set octets zero through 3 of the time_low field to octets zero through 3 of the hash.</li><li>Set octets zero and one of the time_mid field to octets 4 and 5 of the hash.</li><li>Set octets zero and one of the time_hi_and_version field to octets 6 and 7 of the hash.</li><li>Set the four most significant bits (bits 12 through 15) of the time_hi_and_version field to the appropriate 4-bit version number from <a href="#version" title="Version">Section&nbsp;4.1.3</a>.</li><li>Set the clock_seq_hi_and_reserved field to octet 8 of the hash.</li><li>Set the two most significant bits (bits 6 and 7) of the clock_seq_hi_and_reserved to zero and one, respectively.</li><li>Set the clock_seq_low field to octet 9 of the hash.</li><li>Set octets zero through five of the node field to octets 10 through 15 of the hash.</li><li>Convert the resulting UUID to local byte order.</li></ul></div></section><section id="alg-rand"><h3 id="rfc.section.4.4"><a href="#rfc.section.4.4">4.4.</a>&nbsp;<a href="#alg-rand">Algorithms for Creating a UUID from Truly Random or Pseudo-Random Numbers</a></h3><div id="rfc.section.4.4.p.1"><p>The version 4 UUID is meant for generating UUIDs from truly-random or pseudo-random numbers.<a class="self" href="#rfc.section.4.4.p.1">&para;</a></p></div><div id="rfc.section.4.4.p.2"><p>The algorithm is as follows:  <a class="self" href="#rfc.section.4.4.p.2">&para;</a></p><ul><li>Set the two most significant bits (bits 6 and 7) of the clock_seq_hi_and_reserved to zero and one, respectively.</li><li>Set the four most significant bits (bits 12 through 15) of the time_hi_and_version field to the 4-bit version number from <a href="#version" title="Version">Section&nbsp;4.1.3</a>.</li><li>Set all the other bits to randomly (or pseudo-randomly) chosen values.</li></ul></div><div id="rfc.section.4.4.p.3"><p>See <a href="#node-id-no-id" title="Node IDs that Do Not Identify the Host">Section&nbsp;4.5</a> for a discussion on random numbers.<a class="self" href="#rfc.section.4.4.p.3">&para;</a></p></div></section><section id="node-id-no-id"><h3 id="rfc.section.4.5"><a href="#rfc.section.4.5">4.5.</a>&nbsp;<a href="#node-id-no-id">Node IDs that Do Not Identify the Host</a></h3><div id="rfc.section.4.5.p.1"><p>This section describes how to generate a version 1 UUID if an IEEE 802 address is not available, or its use is not desired.<a class="self" href="#rfc.section.4.5.p.1">&para;</a></p></div><div id="rfc.section.4.5.p.2"><p>One approach is to contact the IEEE and get a separate block of addresses. At the time of writing, the application could be found at &lt;<a href="http://standards.ieee.org/regauth/oui/pilot-ind.html">http://standards.ieee.org/regauth/oui/pilot-ind.html</a>&gt;, and the cost was US$550.<a class="self" href="#rfc.section.4.5.p.2">&para;</a></p></div><div id="rfc.section.4.5.p.3"><p>A better solution is to obtain a 47-bit cryptographic quality random number and use it as the low 47 bits of the node ID, with the least significant bit of the first octet of the node ID set to one. This bit is the unicast/multicast bit, which will never be set in IEEE 802 addresses obtained from network cards. Hence, there can never be a conflict between UUIDs generated by machines with and without network cards. (Recall that the IEEE 802 spec talks about transmission order, which is the opposite of the in-memory representation that is discussed in this document.)<a class="self" href="#rfc.section.4.5.p.3">&para;</a></p></div><div id="rfc.section.4.5.p.4"><p>For compatibility with earlier specifications, note that this document uses the unicast/multicast bit, instead of the arguably more correct local/global bit.<a class="self" href="#rfc.section.4.5.p.4">&para;</a></p></div><div id="rfc.section.4.5.p.5"><p>Advice on generating cryptographic-quality random numbers can be found in <a href="#RFC4086">RFC1750</a> <cite title="Randomness Requirements for Security">[5]</cite>.<a class="self" href="#rfc.section.4.5.p.5">&para;</a></p></div><div id="rfc.section.4.5.p.6"><p>In addition, items such as the computer's name and the name of the operating system, while not strictly speaking random, will help differentiate the results from those obtained by other systems.<a class="self" href="#rfc.section.4.5.p.6">&para;</a></p></div><div id="rfc.section.4.5.p.7"><p>The exact algorithm to generate a node ID using these data is system specific, because both the data available and the functions to obtain them are often very system specific. A generic approach, however, is to accumulate as many sources as possible into a buffer, use a message digest such as <a href="#RFC1321">MD5</a> <cite title="The MD5 Message-Digest Algorithm">[4]</cite> or <a href="#FIPS.180-1.1995">SHA-1</a> <cite title="Secure Hash Standard">[8]</cite>, take an arbitrary 6 bytes from the hash value, and set the multicast bit as described above.<a class="self" href="#rfc.section.4.5.p.7">&para;</a></p></div></section></section><section id="community-considerations"><h2 id="rfc.section.5"><a href="#rfc.section.5">5.</a>&nbsp;<a href="#community-considerations">Community Considerations</a></h2><div id="rfc.section.5.p.1"><p>The use of UUIDs is extremely pervasive in computing. They comprise the core identifier infrastructure for many operating systems (Microsoft Windows) and applications (the Mozilla browser) and in many cases, become exposed to the Web in many non-standard ways. This specification attempts to standardize that practice as openly as possible and in a way that attempts to benefit the entire Internet.<a class="self" href="#rfc.section.5.p.1">&para;</a></p></div></section><section id="security-considerations"><h2 id="rfc.section.6"><a href="#rfc.section.6">6.</a>&nbsp;<a href="#security-considerations">Security Considerations</a></h2><div id="rfc.section.6.p.1"><p>Do not assume that UUIDs are hard to guess; they should not be used as security capabilities (identifiers whose mere possession grants access), for example. A predictable random number source will exacerbate the situation.<a class="self" href="#rfc.section.6.p.1">&para;</a></p></div><div id="rfc.section.6.p.2"><p>Do not assume that it is easy to determine if a UUID has been slightly transposed in order to redirect a reference to another object. Humans do not have the ability to easily check the integrity of a UUID by simply glancing at it.<a class="self" href="#rfc.section.6.p.2">&para;</a></p></div><div id="rfc.section.6.p.3"><p>Distributed applications generating UUIDs at a variety of hosts must be willing to rely on the random number source at all hosts. If this is not feasible, the namespace variant should be used.<a class="self" href="#rfc.section.6.p.3">&para;</a></p></div></section><section id="acknowledgments"><h2 id="rfc.section.7"><a href="#rfc.section.7">7.</a>&nbsp;<a href="#acknowledgments">Acknowledgments</a></h2><div id="rfc.section.7.p.1"><p>This document draws heavily on the OSF DCE specification for UUIDs. Ted Ts'o provided helpful comments, especially on the byte ordering section which we mostly plagiarized from a proposed wording he supplied (all errors in that section are our responsibility, however).<a class="self" href="#rfc.section.7.p.1">&para;</a></p></div><div id="rfc.section.7.p.2"><p>We are also grateful to the careful reading and bit-twiddling of Ralf S. Engelschall, John Larmouth, and Paul Thorpe. Professor Larmouth was also invaluable in achieving coordination with ISO/IEC.<a class="self" href="#rfc.section.7.p.2">&para;</a></p></div></section><section id="rfc.references"><h2 id="rfc.section.8"><a href="#rfc.section.8">8.</a> Normative References</h2><dl class="reference"><dt id="NCA">[1]</dt><dd>Zahn, L., Dineen, T., and P. Leach, &#8220;Network Computing Architecture&#8221;, ISBN&nbsp;0-13-611674-4, January&nbsp;1990.</dd><dt id="DCE">[2]</dt><dd>&#8220;DCE: Remote Procedure Call&#8221;, Open Group CAE Specification&nbsp;C309, ISBN&nbsp;1-85912-041-5, August&nbsp;1994.</dd><dt id="itu687">[3]</dt><dd>ISO/IEC 9834-8:2004 Information
            Technology, &#8220;Procedures for the operation of OSI Registration Authorities: Generation and registration of Universally Unique Identifiers (UUIDs) and their use as ASN.1 Object Identifier components&#8221;, ITU-T Rec.&nbsp;X.687, 2004.</dd><dt id="RFC1321">[4]</dt><dd><a href="mailto:rivest@theory.lcs.mit.edu">Rivest, R.</a>, &#8220;<a href="https://tools.ietf.org/html/rfc1321">The MD5 Message-Digest Algorithm</a>&#8221;, RFC&nbsp;1321, April&nbsp;1992.</dd><dt id="RFC4086">[5]</dt><dd>Eastlake, D., Schiller, J., and S. Crocker, &#8220;<a href="https://tools.ietf.org/html/rfc4086">Randomness Requirements for Security</a>&#8221;, BCP&nbsp;106, RFC&nbsp;4086, June&nbsp;2005.</dd><dt id="RFC2141">[6]</dt><dd><a href="mailto:jayhawk@ds.internic.net">Moats, R.</a>, &#8220;<a href="https://tools.ietf.org/html/rfc2141">URN Syntax</a>&#8221;, RFC&nbsp;2141, May&nbsp;1997.</dd><dt id="RFC2234">[7]</dt><dd><a href="mailto:dcrocker@imc.org">Crocker, D., Ed.</a> and <a href="mailto:paulo@turnpike.com">P. Overell</a>, &#8220;<a href="https://tools.ietf.org/html/rfc2234">Augmented BNF for Syntax Specifications: ABNF</a>&#8221;, RFC&nbsp;2234, November&nbsp;1997.</dd><dt id="FIPS.180-1.1995">[8]</dt><dd>National Institute of Standards and Technology, &#8220;<a href="http://www.itl.nist.gov/fipspubs/fip180-1.htm">Secure Hash Standard</a>&#8221;, FIPS&nbsp;PUB 180-1, April&nbsp;1995, &lt;<a href="http://www.itl.nist.gov/fipspubs/fip180-1.htm">http://www.itl.nist.gov/fipspubs/fip180-1.htm</a>&gt;.</dd></dl></section><section id="appendixA"><h2 id="rfc.section.A" class="np"><a href="#rfc.section.A">A.</a>&nbsp;<a href="#appendixA">Appendix A - Sample Implementation</a></h2><div id="rfc.section.A.p.1"><p>This implementation consists of 5 files: uuid.h, uuid.c, sysdep.h, sysdep.c and utest.c. The uuid.* files are the system independent implementation of the UUID generation algorithms described above, with all the optimizations described above except efficient state sharing across processes included. The code has been tested on Linux (Red Hat 4.0) with GCC (2.7.2), and Windows NT 4.0 with VC++ 5.0. The code assumes 64-bit integer support, which makes it much clearer.<a class="self" href="#rfc.section.A.p.1">&para;</a></p></div><div id="rfc.section.A.p.2"><p>All the following source files should have the following copyright notice included:<a class="self" href="#rfc.section.A.p.2">&para;</a></p><span id="rfc.figure.u.7"><pre>
copyrt.h

/*
** Copyright (c) 1990- 1993, 1996 Open Software Foundation, Inc.
** Copyright (c) 1989 by Hewlett-Packard Company, Palo Alto, Ca. &amp;
** Digital Equipment Corporation, Maynard, Mass.
** Copyright (c) 1998 Microsoft.
** To anyone who acknowledges that this file is provided "AS IS"
** without any express or implied warranty: permission to use, copy,
** modify, and distribute this file for any purpose is hereby
** granted without fee, provided that the above copyright notices and
** this notice appears in all source code copies, and that none of
** the names of Open Software Foundation, Inc., Hewlett-Packard
** Company, or Digital Equipment Corporation be used in advertising
** or publicity pertaining to distribution of the software without
** specific, written prior permission. Neither Open Software
** Foundation, Inc., Hewlett-Packard Company, Microsoft, nor Digital
** Equipment Corporation makes any representations about the suitability
** of this software for any purpose.
*/


uuid.h

#include "copyrt.h"
#undef uuid_t
typedef struct {
    unsigned32  time_low;
    unsigned16  time_mid;
    unsigned16  time_hi_and_version;
    unsigned8   clock_seq_hi_and_reserved;
    unsigned8   clock_seq_low;
    byte        node[6];
} uuid_t;

/* uuid_create -- generate a UUID */
int uuid_create(uuid_t * uuid);

/* uuid_create_md5_from_name -- create a version 3 (MD5) UUID using a  
   "name" from a "name space" */
void uuid_create_md5_from_name(
    uuid_t *uuid,         /* resulting UUID */
    uuid_t nsid,          /* UUID of the namespace */
    void *name,           /* the name from which to generate a UUID */
    int namelen           /* the length of the name */
);

/* uuid_create_sha1_from_name -- create a version 5 (SHA-1) UUID 
   using a "name" from a "name space" */
void uuid_create_sha1_from_name(
    uuid_t *uuid,         /* resulting UUID */
    uuid_t nsid,          /* UUID of the namespace */
    void *name,           /* the name from which to generate a UUID */
    int namelen           /* the length of the name */
);

/* uuid_compare --  Compare two UUID's "lexically" and return
        -1   u1 is lexically before u2
         0   u1 is equal to u2
         1   u1 is lexically after u2
   Note that lexical ordering is not temporal ordering!
*/
int uuid_compare(uuid_t *u1, uuid_t *u2);


uuid.c

#include "copyrt.h"
#include &lt;string.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;time.h&gt;
#include "sysdep.h"
#include "uuid.h"

/* various forward declarations */
static int read_state(unsigned16 *clockseq, uuid_time_t *timestamp,
    uuid_node_t *node);
static void write_state(unsigned16 clockseq, uuid_time_t timestamp,
    uuid_node_t node);
static void format_uuid_v1(uuid_t *uuid, unsigned16 clockseq,
    uuid_time_t timestamp, uuid_node_t node);
static void format_uuid_v3or5(uuid_t *uuid, unsigned char hash[16],
    int v);
static void get_current_time(uuid_time_t *timestamp);
static unsigned16 true_random(void);

/* uuid_create -- generator a UUID */
int uuid_create(uuid_t *uuid)
{
     uuid_time_t timestamp, last_time;
     unsigned16 clockseq;
     uuid_node_t node;
     uuid_node_t last_node;
     int f;

     /* acquire system-wide lock so we're alone */
     LOCK;

     /* get time, node ID, saved state from non-volatile storage */
     get_current_time(&amp;timestamp);
     get_ieee_node_identifier(&amp;node);
     f = read_state(&amp;clockseq, &amp;last_time, &amp;last_node);

     /* if no NV state, or if clock went backwards, or node ID 
        changed (e.g., new network card) change clockseq */
     if (!f || memcmp(&amp;node, &amp;last_node, sizeof node))
         clockseq = true_random();
     else if (timestamp &lt; last_time)
         clockseq++;

     /* save the state for next time */
     write_state(clockseq, timestamp, node);

     UNLOCK;

     /* stuff fields into the UUID */
     format_uuid_v1(uuid, clockseq, timestamp, node);
     return 1;
}

/* format_uuid_v1 -- make a UUID from the timestamp, clockseq,
                     and node ID */
void format_uuid_v1(uuid_t* uuid, unsigned16 clock_seq,
                    uuid_time_t timestamp, uuid_node_t node)
{
    /* Construct a version 1 uuid with the information we've gathered
       plus a few constants. */
    uuid-&gt;time_low = (unsigned long)(timestamp &amp; 0xFFFFFFFF);
    uuid-&gt;time_mid = (unsigned short)((timestamp &gt;&gt; 32) &amp; 0xFFFF);
    uuid-&gt;time_hi_and_version =
        (unsigned short)((timestamp &gt;&gt; 48) &amp; 0x0FFF);
    uuid-&gt;time_hi_and_version |= (1 &lt;&lt; 12);
    uuid-&gt;clock_seq_low = clock_seq &amp; 0xFF;
    uuid-&gt;clock_seq_hi_and_reserved = (clock_seq &amp; 0x3F00) &gt;&gt; 8;
    uuid-&gt;clock_seq_hi_and_reserved |= 0x80;
    memcpy(&amp;uuid-&gt;node, &amp;node, sizeof uuid-&gt;node);
}

/* data type for UUID generator persistent state */
typedef struct {
    uuid_time_t  ts;       /* saved timestamp */
    uuid_node_t  node;     /* saved node ID */
    unsigned16   cs;       /* saved clock sequence */
} uuid_state;

static uuid_state st;

/* read_state -- read UUID generator state from non-volatile store */
int read_state(unsigned16 *clockseq, uuid_time_t *timestamp,
               uuid_node_t *node)
{
    static int inited = 0;
    FILE *fp;

    /* only need to read state once per boot */
    if (!inited) {
        fp = fopen("state", "rb");
        if (fp == NULL)
            return 0;
        fread(&amp;st, sizeof st, 1, fp);
        fclose(fp);
        inited = 1;
    }
    *clockseq = st.cs;
    *timestamp = st.ts;
    *node = st.node;
    return 1;
}

/* write_state -- save UUID generator state back to non-volatile
   storage */
void write_state(unsigned16 clockseq, uuid_time_t timestamp,
                 uuid_node_t node)
{
    static int inited = 0;
    static uuid_time_t next_save;
    FILE* fp;

    if (!inited) {
        next_save = timestamp;
        inited = 1;
    }

    /* always save state to volatile shared state */
    st.cs = clockseq;
    st.ts = timestamp;
    st.node = node;
    if (timestamp &gt;= next_save) {
        fp = fopen("state", "wb");
        fwrite(&amp;st, sizeof st, 1, fp);
        fclose(fp);
        /* schedule next save for 10 seconds from now */
        next_save = timestamp + (10 * 10 * 1000 * 1000);
    }
}

/* get-current_time -- get time as 60-bit 100ns ticks since UUID epoch.
   Compensate for the fact that real clock resolution is
   less than 100ns. */
void get_current_time(uuid_time_t *timestamp)
{
    static int inited = 0;
    static uuid_time_t time_last;
    static unsigned16 uuids_this_tick;
    uuid_time_t time_now;

    if (!inited) {
        get_system_time(&amp;time_now);
        uuids_this_tick = UUIDS_PER_TICK;
        inited = 1;
    }

    for ( ; ; ) {
        get_system_time(&amp;time_now);

        /* if clock reading changed since last UUID generated, */
        if (time_last != time_now) {
            /* reset count of uuids gen'd with this clock reading */
            uuids_this_tick = 0;
            time_last = time_now;
            break;
        }
        if (uuids_this_tick &lt; UUIDS_PER_TICK) {
            uuids_this_tick++;
            break;
        }
        /* going too fast for our clock; spin */
    }
    /* add the count of uuids to low order bits of the clock reading */
    *timestamp = time_now + uuids_this_tick;
}

/* true_random -- generate a crypto-quality random number.
   **This sample doesn't do that.** */
static unsigned16 true_random(void)
{
    static int inited = 0;
    uuid_time_t time_now;

    if (!inited) {
        get_system_time(&amp;time_now);
        time_now = time_now / UUIDS_PER_TICK;
        srand((unsigned int)
               (((time_now &gt;&gt; 32) ^ time_now) &amp; 0xffffffff));
        inited = 1;
    }

    return rand();
}

/* uuid_create_md5_from_name -- create a version 3 (MD5) UUID using a
   "name" from a "name space" */
void uuid_create_md5_from_name(uuid_t *uuid, uuid_t nsid, void *name,
                               int namelen)
{
    MD5_CTX c;
    unsigned char hash[16];
    uuid_t net_nsid;

    /* put name space ID in network byte order so it hashes the same
       no matter what endian machine we're on */
    net_nsid = nsid;
    net_nsid.time_low = htonl(net_nsid.time_low);
    net_nsid.time_mid = htons(net_nsid.time_mid);
    net_nsid.time_hi_and_version = htons(net_nsid.time_hi_and_version);

    MD5Init(&amp;c);
    MD5Update(&amp;c, &amp;net_nsid, sizeof net_nsid);
    MD5Update(&amp;c, name, namelen);
    MD5Final(hash, &amp;c);

    /* the hash is in network byte order at this point */
    format_uuid_v3or5(uuid, hash, 3);
}

void uuid_create_sha1_from_name(uuid_t *uuid, uuid_t nsid, void *name,
                                int namelen)
{
    SHA_CTX c;
    unsigned char hash[20];
    uuid_t net_nsid;

    /* put name space ID in network byte order so it hashes the same
       no matter what endian machine we're on */
    net_nsid = nsid;
    net_nsid.time_low = htonl(net_nsid.time_low);
    net_nsid.time_mid = htons(net_nsid.time_mid);
    net_nsid.time_hi_and_version = htons(net_nsid.time_hi_and_version);

    SHA1_Init(&amp;c);
    SHA1_Update(&amp;c, &amp;net_nsid, sizeof net_nsid);
    SHA1_Update(&amp;c, name, namelen);
    SHA1_Final(hash, &amp;c);

    /* the hash is in network byte order at this point */
    format_uuid_v3or5(uuid, hash, 5);
}

/* format_uuid_v3or5 -- make a UUID from a (pseudo)random 128-bit
   number */
void format_uuid_v3or5(uuid_t *uuid, unsigned char hash[16], int v)
{
    /* convert UUID to local byte order */
    memcpy(uuid, hash, sizeof *uuid);
    uuid-&gt;time_low = ntohl(uuid-&gt;time_low);
    uuid-&gt;time_mid = ntohs(uuid-&gt;time_mid);
    uuid-&gt;time_hi_and_version = ntohs(uuid-&gt;time_hi_and_version);

    /* put in the variant and version bits */
    uuid-&gt;time_hi_and_version &amp;= 0x0FFF;
    uuid-&gt;time_hi_and_version |= (v &lt;&lt; 12);
    uuid-&gt;clock_seq_hi_and_reserved &amp;= 0x3F;
    uuid-&gt;clock_seq_hi_and_reserved |= 0x80;
}

/* uuid_compare --  Compare two UUID's "lexically" and return */
#define CHECK(f1, f2) if (f1 != f2) return f1 &lt; f2 ? -1 : 1;
int uuid_compare(uuid_t *u1, uuid_t *u2)
{
    int i;

    CHECK(u1-&gt;time_low, u2-&gt;time_low);
    CHECK(u1-&gt;time_mid, u2-&gt;time_mid);
    CHECK(u1-&gt;time_hi_and_version, u2-&gt;time_hi_and_version);
    CHECK(u1-&gt;clock_seq_hi_and_reserved, u2-&gt;clock_seq_hi_and_reserved);
    CHECK(u1-&gt;clock_seq_low, u2-&gt;clock_seq_low)
    for (i = 0; i &lt; 6; i++) {
        if (u1-&gt;node[i] &lt; u2-&gt;node[i])
            return -1;
        if (u1-&gt;node[i] &gt; u2-&gt;node[i])
            return 1;
    }
    return 0;
}
#undef CHECK


sysdep.h

#include "copyrt.h"
/* remove the following define if you aren't running WIN32 */
#define WININC 0

#ifdef WININC
#include &lt;windows.h&gt;
#else
#include &lt;sys/types.h&gt;
#include &lt;sys/time.h&gt;
#include &lt;sys/sysinfo.h&gt;
#endif

#include "global.h"
/* change to point to where MD5 .h's live; RFC 1321 has sample
   implementation */
#include "md5.h"

/* set the following to the number of 100ns ticks of the actual
   resolution of your system's clock */
#define UUIDS_PER_TICK 1024

/* Set the following to a calls to get and release a global lock */
#define LOCK
#define UNLOCK

typedef unsigned long   unsigned32;
typedef unsigned short  unsigned16;
typedef unsigned char   unsigned8;
typedef unsigned char   byte;

/* Set this to what your compiler uses for 64-bit data type */
#ifdef WININC
#define unsigned64_t unsigned __int64
#define I64(C) C
#else
#define unsigned64_t unsigned long long
#define I64(C) C##LL
#endif

typedef unsigned64_t uuid_time_t;
typedef struct {
    char nodeID[6];
} uuid_node_t;

void get_ieee_node_identifier(uuid_node_t *node);
void get_system_time(uuid_time_t *uuid_time);
void get_random_info(char seed[16]);


sysdep.c

#include "copyrt.h"
#include &lt;stdio.h&gt;
#include "sysdep.h"

/* system dependent call to get IEEE node ID.
   This sample implementation generates a random node ID. */
void get_ieee_node_identifier(uuid_node_t *node)
{
    static inited = 0;
    static uuid_node_t saved_node;
    char seed[16];
    FILE *fp;

    if (!inited) {
        fp = fopen("nodeid", "rb");
        if (fp) {
            fread(&amp;saved_node, sizeof saved_node, 1, fp);
            fclose(fp);
        }
        else {
            get_random_info(seed);
            seed[0] |= 0x01;
            memcpy(&amp;saved_node, seed, sizeof saved_node);
            fp = fopen("nodeid", "wb");
            if (fp) {
                fwrite(&amp;saved_node, sizeof saved_node, 1, fp);
                fclose(fp);
            }
        }
        inited = 1;
    }

    *node = saved_node;
}

/* system dependent call to get the current system time. Returned as
   100ns ticks since UUID epoch, but resolution may be less than
   100ns. */
#ifdef _WINDOWS_

void get_system_time(uuid_time_t *uuid_time)
{
    ULARGE_INTEGER time;

    /* NT keeps time in FILETIME format which is 100ns ticks since
       Jan 1, 1601. UUIDs use time in 100ns ticks since Oct 15, 1582.
       The difference is 17 Days in Oct + 30 (Nov) + 31 (Dec)
       + 18 years and 5 leap days. */
    GetSystemTimeAsFileTime((FILETIME *)&amp;time); 
    time.QuadPart +=
          (unsigned __int64) (1000*1000*10)       // seconds
        * (unsigned __int64) (60 * 60 * 24)       // days
        * (unsigned __int64) (17+30+31+365*18+5); // # of days
    *uuid_time = time.QuadPart;
}

/* Sample code, not for use in production; see RFC 1750 */
void get_random_info(char seed[16])
{
    MD5_CTX c;
    struct {
        MEMORYSTATUS m;
        SYSTEM_INFO s;
        FILETIME t;
        LARGE_INTEGER pc;
        DWORD tc;
        DWORD l;
        char hostname[MAX_COMPUTERNAME_LENGTH + 1];
    } r;

    MD5Init(&amp;c);
    GlobalMemoryStatus(&amp;r.m);
    GetSystemInfo(&amp;r.s);
    GetSystemTimeAsFileTime(&amp;r.t);
    QueryPerformanceCounter(&amp;r.pc);
    r.tc = GetTickCount();
    r.l = MAX_COMPUTERNAME_LENGTH + 1;
    GetComputerName(r.hostname, &amp;r.l);
    MD5Update(&amp;c, &amp;r, sizeof r);
    MD5Final(seed, &amp;c);
}

#else

void get_system_time(uuid_time_t *uuid_time)
{
    struct timeval tp;

    gettimeofday(&amp;tp, (struct timezone *)0);

    /* Offset between UUID formatted times and Unix formatted times.
       UUID UTC base time is October 15, 1582.
       Unix base time is January 1, 1970.*/
    *uuid_time = ((unsigned64)tp.tv_sec * 10000000)
        + ((unsigned64)tp.tv_usec * 10)
        + I64(0x01B21DD213814000);
}

/* Sample code, not for use in production; see RFC 1750 */
void get_random_info(char seed[16])
{
    MD5_CTX c;
    struct {
        struct sysinfo s;
        struct timeval t;
        char hostname[257];
    } r;

    MD5Init(&amp;c);
    sysinfo(&amp;r.s);
    gettimeofday(&amp;r.t, (struct timezone *)0);
    gethostname(r.hostname, 256);
    MD5Update(&amp;c, &amp;r, sizeof r);
    MD5Final(seed, &amp;c);
}

#endif

utest.c

#include "copyrt.h"
#include "sysdep.h"
#include &lt;stdio.h&gt;
#include "uuid.h"

uuid_t NameSpace_DNS = { /* 6ba7b810-9dad-11d1-80b4-00c04fd430c8 */
    0x6ba7b810,
    0x9dad,
    0x11d1,
    0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8
};

/* puid -- print a UUID */
void puid(uuid_t u)
{
    int i;

    printf("%8.8x-%4.4x-%4.4x-%2.2x%2.2x-", u.time_low, u.time_mid,
    u.time_hi_and_version, u.clock_seq_hi_and_reserved,
    u.clock_seq_low);
    for (i = 0; i &lt; 6; i++)
        printf("%2.2x", u.node[i]);
    printf("\n");
}

/* Simple driver for UUID generator */
void main(int argc, char **argv)
{
    uuid_t u;
    int f;

    uuid_create(&amp;u);
    printf("uuid_create(): "); puid(u);

    f = uuid_compare(&amp;u, &amp;u);
    printf("uuid_compare(u,u): %d\n", f);     /* should be 0 */
    f = uuid_compare(&amp;u, &amp;NameSpace_DNS);
    printf("uuid_compare(u, NameSpace_DNS): %d\n", f); /* s.b. 1 */
    f = uuid_compare(&amp;NameSpace_DNS, &amp;u);
    printf("uuid_compare(NameSpace_DNS, u): %d\n", f); /* s.b. -1 */
    uuid_create_md5_from_name(&amp;u, NameSpace_DNS, "www.widgets.com", 15);
    printf("uuid_create_md5_from_name(): "); puid(u);
}
</pre></span></div></section><section id="appendixB"><h2 id="rfc.section.B"><a href="#rfc.section.B">B.</a>&nbsp;<a href="#appendixB">Appendix B - Sample Output of utest</a></h2><div id="rfc.section.B.p.1"><span id="rfc.figure.u.8"><pre>
  uuid_create(): 7d444840-9dc0-11d1-b245-5ffdce74fad2
  uuid_compare(u,u): 0
  uuid_compare(u, NameSpace_DNS): 1
  uuid_compare(NameSpace_DNS, u): -1
  uuid_create_md5_from_name(): e902893a-9d22-3c7e-a7b8-d6e313b71d9f
</pre></span></div></section><section id="appendixC"><h2 id="rfc.section.C"><a href="#rfc.section.C">C.</a>&nbsp;<a href="#appendixC">Appendix C - Some Name Space IDs</a></h2><div id="rfc.section.C.p.1"><p>This appendix lists the name space IDs for some potentially interesting name spaces, as initialized C structures and in the string representation defined above. <a class="self" href="#rfc.section.C.p.1">&para;</a></p><span id="rfc.figure.u.9"><pre>
/* Name string is a fully-qualified domain name */
uuid_t NameSpace_DNS = { /* 6ba7b810-9dad-11d1-80b4-00c04fd430c8 */
    0x6ba7b810,
    0x9dad,
    0x11d1,
    0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8
};

/* Name string is a URL */
uuid_t NameSpace_URL = { /* 6ba7b811-9dad-11d1-80b4-00c04fd430c8 */
    0x6ba7b811,
    0x9dad,
    0x11d1,
    0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8
};

/* Name string is an ISO OID */
uuid_t NameSpace_OID = { /* 6ba7b812-9dad-11d1-80b4-00c04fd430c8 */
    0x6ba7b812,
    0x9dad,
    0x11d1,
    0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8
};

/* Name string is an X.500 DN (in DER or a text output format) */
uuid_t NameSpace_X500 = { /* 6ba7b814-9dad-11d1-80b4-00c04fd430c8 */
    0x6ba7b814,
    0x9dad,
    0x11d1,
    0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8
};
</pre></span></div></section><section id="rfc.authors" class="avoidbreakinside"><h2><a href="#rfc.authors">Authors' Addresses</a></h2><address><b>Paul J. Leach</b><br>Microsoft<br>1 Microsoft Way<br>Redmond, WA&nbsp;98052<br>US<br>Phone: <a href="tel:+1425-882-8080">+1 425-882-8080</a><br>EMail: <a href="mailto:paulle@microsoft.com">paulle@microsoft.com</a></address><address><b>Michael Mealling</b><br>Refactored Networks, LLC<br>1635 Old Hwy 41<br>Suite 112, Box 138<br>Kennesaw, GA&nbsp;30152<br>US<br>Phone: <a href="tel:+1-678-581-9656">+1-678-581-9656</a><br>EMail: <a href="mailto:michael@refactored-networks.com">michael@refactored-networks.com</a><br>URI: <a href="http://www.refactored-networks.com">http://www.refactored-networks.com</a></address><address><b>Rich Salz</b><br>DataPower Technology, Inc.<br>1 Alewife Center<br>Cambridge, MA&nbsp;02142<br>US<br>Phone: <a href="tel:+1617-864-0455">+1 617-864-0455</a><br>EMail: <a href="mailto:rsalz@datapower.com">rsalz@datapower.com</a><br>URI: <a href="http://www.datapower.com">http://www.datapower.com</a></address></section><section id="rfc.copyright"><h2><a href="#rfc.copyright">Full Copyright Statement</a></h2><p>Copyright &copy; The Internet Society (2005).</p><p>This document is subject to the rights, licenses and restrictions contained in BCP 78, and except as set forth therein, the authors retain all their rights.</p><p>This document and the information contained herein are provided on an &#8220;AS IS&#8221; basis and THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY AND THE INTERNET ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.</p></section><section id="rfc.ipr"><h2><a href="#rfc.ipr">Intellectual Property</a></h2><p>The IETF takes no position regarding the validity or scope of any Intellectual Property Rights or other rights that might be claimed to pertain to the implementation or use of the technology described in this document or the extent to which any license under such rights might or might not be available; nor does it represent that it has made any independent effort to identify any such rights. Information on the procedures with respect to rights in RFC documents can be found in BCP 78 and BCP 79.</p><p>Copies of IPR disclosures made to the IETF Secretariat and any assurances of licenses to be made available, or the result of an attempt made to obtain a general license or permission for the use of such proprietary rights by implementers or users of this specification can be obtained from the IETF on-line IPR repository at <a href="http://www.ietf.org/ipr">http://www.ietf.org/ipr</a>.</p><p>The IETF invites any interested party to bring to its attention any copyrights, patents or patent applications, or other proprietary rights that may cover technology that may be required to implement this standard. Please address the information to the IETF at <a href="mailto:ietf-ipr@ietf.org">ietf-ipr@ietf.org</a>.</p></section><section id="n-acknowledgment"><h2><a href="#n-acknowledgment">Acknowledgment</a></h2><p>Funding for the RFC Editor function is currently provided by the Internet Society.</p></section></body></html>
